local key = KEYS[1] -- comment:list:noteId(xxx)
local batchSize = #ARGV / 2 -- 评论数
local maxSize = 100

if redis.call('EXISTS', key) == 0 then
    return -1
end

for i = 1, batchSize do
    local member = ARGV[(i - 1) * 2 + 1]    -- 评论id
    local score = ARGV[(i - 1) * 2 + 2]      -- 评论热度

    local currentScore = redis.call('ZSCORE', key, member)
    if currentScore < maxSize then
        redis.call('ZADD', key, score, member)
    else -- 热点评论数已经有 100条
        local minEntry = redis.call('ZRANGE', key, 0, 0, 'WITHSCORES')
        local minScore = minEntry[2]

        if minScore < score then
            redis.call('ZREM', key, minEntry[1])
            redis.call('ZADD', key, score, member)
        end
    end

end